/**
 * @file LGSolver.h
 * @author shikang999@126.com
 * @brief 自研启发式求解器
 * @version 0.1
 * @date 2025-06-25
 * 
 * @copyright Copyright (c) 2025
 * 
 */
#pragma once
#include "BaseSolver.h"

namespace Solver
{
class LGSolver: public BaseSolver
{
public:
    LGSolver();
    ~LGSolver();

    //是否开启梯度搜索
    void openDiffSearch(bool open);
    
private:
    //初始化一些参数
    bool init() final;

    //迭代求解
    void solveByIter() final;

    //将变量压入候选解
    void pushVar(const VectorXd_t &x);

    VectorXd_t& getRandX(bool needWaitVar);

    //更新一些参数
    void updateParam();
    
    //对前几个变量进行局部搜索
    bool searchBest();

    //再次搜索
    bool searchAgain();

    //搜索值
    bool searchVar(std::shared_ptr<Variable_t>& var, bool forceUpdate);

private:
    bool needDiffSearch_;  //是否开启梯度搜索
    uint16_t upIter_;
    std::size_t maxWaitNum_;//最大后续种群数量
    value_t upY_;
    value_t upR_;
    std::size_t waitVarIndex_;
    VectorXd_t  vecAvg_;
    vecDataValue_t vecWaitVar_;
};

}